//
//  XYTabarController.m
//  新项目
//
//  Created by xmy on 2017/2/22.
//  Copyright © 2017年 xmy. All rights reserved.
//

#import "XYTabarController.h"
#import "XYNavigationController.h"
#import "WBTabBar.h"

#define Screen_Height [UIScreen mainScreen].bounds.size.height
#define Screen_Width [UIScreen mainScreen].bounds.size.width
#define KSIZE ([UIScreen mainScreen].bounds.size)
#define baseTag 10

@interface XYTabarController ()<UIScrollViewDelegate,UIAlertViewDelegate>

@end

@implementation XYTabarController
{
    UIScrollView * _scroll;
    UIButton * btn1;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //设置tabBar为自定义的tabBar
    WBTabBar *tabBar = [[WBTabBar alloc] init];
    [self setValue:tabBar forKey:@"tabBar"];
    //设置tabBar中间按钮的点击效果
    tabBar.composeBtnClickBlock = ^{
        NSLog(@"点击了tabBar中间的按钮");
    };

    //文字颜色
    self.tabBar.tintColor = [UIColor orangeColor];
    [self addChildViewControllers];
}

- (void)addChildViewControllers{
    
        //文字颜色
    self.tabBar.tintColor = [UIColor orangeColor];
    
    UIViewController *vc1 = [self childViewController:@"XYHomeViewController" title:@"首页" imageName:@"tabbar_home"];
    UIViewController *vc2 = [self childViewController:@"XYShopCenterViewController" title:@"商城" imageName:@"tabbar_message_center"];
    
    UIViewController *vc4 = [self childViewController:@"XYAnswerViewController" title:@"你问我答" imageName:@"tabbar_discover"];
    UIViewController *vc5 = [self childViewController:@"XYMineViewController" title:@"美吧" imageName:@"tabbar_profile"];
    [self addChildViewController:vc1];
    [self addChildViewController:vc2];
    
    [self addChildViewController:vc4];
    [self addChildViewController:vc5];

}

- (UIViewController *)childViewController:(NSString  *)controllerName title:(NSString *)title imageName:(NSString *)imageName {
    
    UIViewController *vc = [NSClassFromString(controllerName) new];
    
//    vc.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    
    [vc.tabBarItem setSelectedImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]]];
    
    XYNavigationController *nav = [[XYNavigationController alloc]initWithRootViewController:vc];
    return nav;
}


@end
